﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.RequestModels.Brand;
using Ekton_Manage_IBusiness;
using Ekton_Manage_InfrastructureCore.Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Ekton_Manage_Web.Controllers
{
    /// <summary>
    /// 品牌信息
    /// </summary>
    /// 
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize("Permission")]
    public class BrandController : ControllerBase
    {
        private readonly IBrandBusiness _brandBusiness;

        public BrandController(IBrandBusiness brandBusiness)
        {
            _brandBusiness = brandBusiness;
        }

        /// <summary>
        /// 查询全部品牌信息
        /// </summary>
        /// 
        [HttpGet]
        public async Task<MessageModel<PageModel<brand_msg>>> GetBrandList([FromQuery] QueryDataParame query)
        {
            var result = await _brandBusiness.GetBrandList(query);
            return new MessageModel<PageModel<brand_msg>>
            {
                msg = "数据获取成功",
                response = new PageModel<brand_msg>
                {
                    pageIndex = query.pageIndex,
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.Item2) / query.pageSize)),
                    dataCount = result.Item2,
                    pageSize = query.pageSize,
                    data = result.Item1
                }
            };
        }

        /// <summary>
        /// 编辑品牌信息
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PutBrandInfo([FromBody] DtoBrandInfo request)
        {
            return await _brandBusiness.PutBrandInfo(request);

        }

        /// <summary>
        /// 添加品牌信息
        /// </summary>
        /// 
        [HttpPost]
        public async Task<Message> PostBrandInfo([FromBody] DtoBrandInfo request)
        {
            return await _brandBusiness.PostBrandInfo(request);
        }


        /// <summary>
        /// 删除品牌信息
        /// </summary>
        /// 
        [HttpDelete("{id}")]
        public async Task<Message> DeleteBrandInfo(int id)
        {
            return await _brandBusiness.DeleteBrandInfo(id);
        }

        /// <summary>
        /// 查询序列信息
        /// </summary>
        /// 
        [HttpGet]
        public async Task<MessageModel<PageModel<series_msg>>> GetSequenceInfo([FromQuery] QueryDataParame query)
        {
            var result = await _brandBusiness.GetSequenceInfo(query);
            return new MessageModel<PageModel<series_msg>>
            {
                msg = "数据获取成功",
                response = new PageModel<series_msg>
                {
                    pageIndex = query.pageIndex,
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.Item2) / query.pageSize)),
                    dataCount = result.Item2,
                    pageSize = query.pageSize,
                    data = result.Item1
                }
            };
        }

        /// <summary>
        /// 编辑序列信息
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PutSequenceInfo([FromBody] DtoSequenceInfo request)
        {
            return await _brandBusiness.PutSequenceInfo(request);
        }

        /// <summary>
        /// 添加序列信息
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PostSequenceInfo([FromBody] DtoSequenceInfo request)
        {
            return await _brandBusiness.PostSequenceInfo(request);
        }

        /// <summary>
        /// 删除序列信息
        /// </summary>
        /// 
        [HttpDelete("{id}")]
        public async Task<Message> DeleteSequenceInfo(int id)
        {
            return await _brandBusiness.DeleteSequenceInfo(id);
        }

        /// <summary>
        /// 查询平台信息
        /// </summary>
        /// 
        [HttpGet]
        public async Task<MessageModel<PageModel<platform_msg>>> GetPlatformInfo([FromQuery] QueryDataParame query)
        {
            var result = await _brandBusiness.GetPlatformInfo(query);
            return new MessageModel<PageModel<platform_msg>>
            {
                msg = "数据获取成功",
                response = new PageModel<platform_msg>
                {
                    pageIndex = query.pageIndex,
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.Item2) / query.pageSize)),
                    dataCount = result.Item2,
                    pageSize = query.pageSize,
                    data = result.Item1
                }
            };
        }


        /// <summary>
        /// 编辑平台信息
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PutPlatformInfo([FromBody] DtoPlatformInfo request)
        {
            return await _brandBusiness.PutPlatformInfo(request);
        }


        /// <summary>
        /// 添加平台信息
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PostPlatformInfo([FromBody] DtoPlatformInfo request)
        {
            return await _brandBusiness.PostPlatformInfo(request);
        }


        /// <summary>
        /// 删除平台信息
        /// </summary>
        /// 
        [HttpDelete("{id}")]
        public async Task<Message> DeletePlatformInfo(int id)
        {
            return await _brandBusiness.DeletePlatformInfo(id);
        }
    }
}
